﻿using CPPEI.Coolzon.Metadata;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.DataProvider
{
    /// <summary>
    /// 数据提供对象的创建工厂
    /// </summary>
    public class DataProviderFactory
    {
        #region 测试配置，以后此信息通过配置文件来读取
        private static string _mockAssembly = "CPPEI.Coolzon.DataProvider.SQL.dll";
        //private static string _mockClassName = "CPPEI.Coolzon.DataProvider.SQL.OracleDataProvider";
        private static string _mockClassName = "CPPEI.Coolzon.DataProvider.SQL.SqlDataProvider";
        #endregion

        /// <summary>
        /// 根据数据源的类型来创建数据提供对象
        /// </summary>
        /// <param name="dataSource">数据源定义</param>
        /// <returns></returns>
        public static IDataProvider Create(DataSource dataSource)
        {
            Assembly assembly = Assembly.LoadFile(string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, _mockAssembly));

            object objParser = assembly.CreateInstance(_mockClassName);

            return (IDataProvider)objParser;
        }
    }
}
